package com.wangzhen.spring.bean.factory;

import com.wangzhen.spring.ioc.dependcy.entity.User;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author dell
 * @since 2020/10/27 8:34
 */
public class DefaultUserFactory implements UserFactory, InitializingBean, DisposableBean {

    @Override
    public User createUser() {
        return User.createUser();
    }

    @PostConstruct
    public void postConstructInit() {
        System.out.println("------------------defaultUserFactory init by @PostConstruct");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("------------------defaultUserFactory init by afterPropertiesSet");
    }

    public void initMethod() {
        System.out.println("------------------defaultUserFactory init by initMethod");
    }

    @PreDestroy
    public void preDestory() {
        System.out.println("------------------defaultUserFactory destory by preDestory");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("------------------defaultUserFactory destory by DisposableBean#destory");
    }

    /**
     * 自定义destory方法
     */
    public void destoryMethod(){
        System.out.println("------------------defaultUserFactory destory by destoryMethod");
    }
}
